<template>
	<div>
		<el-dialog title="车辆信息" v-model="comFormShow" size="small">
			<el-row :gutter="24">
				<el-col :span="2" style="margin-right:10px;">
					<p class="queryLabel">查询方式:</p>
				</el-col>
				<el-col :span="6">
					<el-select size="small" v-model="conditions.key" placeholder="选择查询方法">
						<el-option v-for="item in moduleCombo" :label="item.label" :value="item.value">
						</el-option>
					</el-select>
				</el-col>
				<el-col :span="2" style="margin-right:10px;">
					<p class="queryLabel">查询内容:</p>
				</el-col>
				<el-col :span="6">
					<el-input size="small" style="margin-left:15px;" v-model="conditions.value" placeholder="请输入内容">
					</el-input>
				</el-col>
				<el-col :span="4" style="padding-left: 0px;text-align: right">
					<el-button type="primary" size="small" v-on:click='carQuery'>查询</el-button>
				</el-col>
			</el-row>
			<el-row>
				<el-col :span="24">
					<el-card class="box-card">
						<el-form :model="comFormData" ref="comForm" label-width="100px">
							<el-col :span="12">
								<el-form-item label="车牌号：" prop="plateNum" required>
									<el-input size="small" v-model="comFormData.plateNum" readonly></el-input>
								</el-form-item>
							</el-col>
							<el-col :span="12">
								<el-form-item label="车型：" prop="carModel" required>
									<el-input size="small" v-model="comFormData.carModel" readonly></el-input>
								</el-form-item>
							</el-col>
							<el-col :span="12">
								<el-form-item label="VIN：" prop="vin" required>
									<el-input size="small" v-model="comFormData.vin" readonly></el-input>
								</el-form-item>
							</el-col>
							<el-col :span="12">
								<el-form-item label="车龄：" prop="carAge" required>
									<el-input size="small" v-model="comFormData.carAge" readonly></el-input>
								</el-form-item>
							</el-col>
							<el-col :span="12">
								<el-form-item label="被保险人：" prop="insured" required>
									<el-input size="small" v-model="comFormData.insured" placeholder="请输入被保险人"></el-input>
								</el-form-item>
							</el-col>
							<el-col :span="12">
								<el-form-item label="联系电话：" prop="contactPhone" required>
									<el-input size="small" v-model="comFormData.contactPhone" placeholder="请输入联系电话"></el-input>
								</el-form-item>
							</el-col>
							<el-col :span="12">
								<el-form-item label="投保公司：" prop="insuranceCompany">
									<el-input size="small" v-model="comFormData.insuranceCompany" placeholder="请输入投保公司"></el-input>
								</el-form-item>
							</el-col>
							<el-col :span="12">
								<el-form-item label="保险到期日：" prop="insuranceEndDate">
									<el-input size="small" v-model="comFormData.insuranceEndDate" placeholder="请输入保险到期日"></el-input>
								</el-form-item>
							</el-col>
						</el-form>
					</el-card>
				</el-col>
			</el-row>
			<el-row :gutter="24">
				<el-col :span="24">
					<el-form ref="comForm" label-width="120px">
						<el-form-item label="投保类别：" prop="insureType" required v-if="QuotationFrom.paramQuotation.carId">
							<el-col :span="12">
								<el-select size="small" style="width: 100%;" v-model="QuotationFrom.paramQuotation.insureType" placeholder="请选择保险类别" clearable>
									<el-option label="新保" value="sb"></el-option>
									<el-option label="续保" value="xb"></el-option>
								</el-select>
							</el-col>
						</el-form-item>
						<el-form-item label="投保起始日：" prop="insuranceStartDate" required v-if="QuotationFrom.paramQuotation.carId">
							<el-col :span="12">
								<el-date-picker size="small" style="width: 100%; margin-left: 4px;" v-model="QuotationFrom.paramQuotation.insuranceStartDate" format="yyyy-MM-dd" type="date" placeholder="开始时间">
								</el-date-picker>
							</el-col>
						</el-form-item>
						<el-form-item label="保险公司：" prop="insuranceCompanyId" required v-if="QuotationFrom.paramQuotation.carId">
							<el-col :span="12">
								<el-select size="small" v-model="QuotationFrom.paramQuotation.insuranceCompanyId" placeholder="选择保险公司">
									<el-option v-for="item in companyCombo" :label="item.label" :value="item.value">
									</el-option>
								</el-select>
							</el-col>
						</el-form-item>
					</el-form>
				</el-col>
			</el-row>
			<div slot="footer" class="dialog-footer" v-if="QuotationFrom.paramQuotation.carId">
				<el-button @click="comFormShow = false">取 消</el-button>
				<el-button type="primary" v-on:click='save'>提 交</el-button>
			</div>
		</el-dialog>
	</div>
</template>

<script>
	import '../Insurance/config/insOrder.vue'
	export default{
		prop:{
			comFormShow:false
		},
		watch:{
			comFormShow:function(start){
				debugger;
				if(!start){
					this.$emit('close');
				}
			},
		},
		data: function() {
			return {
				//新增时的车辆查询条件
				conditions: {
					key: "",
					value: ""
				},
				comFormData: {
					insured: "",
					carAge: '',
					passengerWeight: "",
					contactName: "",
					engineNum: "",
					updateUser: "",
					updateTime: "",
					firstRecordDate: "",
					plateNum: "",
					insuredIDNumber: "",
					realValue: "",
					companyId: "",
					carType: "",
					createTime: "",
					useProperty: "",
					driverLicense: "",
					createUser: "",
					vin: "",
					postCode: "",
					id: "",
					insuredAddress: "",
					power: "",
					contactPhone: "",
					email: "",
					carModel: "",
					insuranceCompany: "",
					insuranceEndDate: ""
				},
				emptyData: {
					insured: "",
					carAge: '',
					passengerWeight: "",
					contactName: "",
					engineNum: "",
					updateUser: "",
					updateTime: "",
					firstRecordDate: "",
					plateNum: "",
					insuredIDNumber: "",
					realValue: "",
					companyId: "",
					carType: "",
					createTime: "",
					useProperty: "",
					driverLicense: "",
					createUser: "",
					vin: "",
					postCode: "",
					id: "",
					insuredAddress: "",
					power: "",
					contactPhone: "",
					email: "",
					carModel: "",
					insuranceCompany: "",
					insuranceEndDate: ""
				},
				QuotationFrom: {
					paramQuotation: {
						carId: "", //车辆ID
						carAge: '', //车龄
						insuranceCompanyId: "", //保险公司ID
						contactPeople: "", //联系人
						contactPhone: "", //联系电话
						insuranceStartDate: "", //保险起始日期
						insuranceStopDate: "", //保险终止日期
						ompulsoryTotal: "", //交强险总价
						commercialinsuranceTotal: "", //商业险总价
						remark: "", //备注
						insureType: '', //投保类别
					},
					insurance: ''
				},
				emptyQuotationFrom: {
					paramQuotation: {
						carId: "", //车辆ID
						carAge: '', //车龄
						insuranceCompanyId: "", //保险公司ID
						contactPeople: "", //联系人
						contactPhone: "", //联系电话
						insuranceStartDate: "", //保险起始日期
						insuranceStopDate: "", //保险终止日期
						ompulsoryTotal: "", //交强险总价
						commercialinsuranceTotal: "", //商业险总价
						remark: "", //备注
						insureType: '', //投保类别
					},
					insurance: ''
				},
				
			}
		},
		methods:{
			//查询车辆
			carQuery: function() {
				this.$http({
					method: 'POST',
					url: this.API_ROOT + '/insurance/car/info',
					params: {
						key: this.$data.conditions.key,
						value: this.$data.conditions.value,
					}
				}).then(function(resp) {
					if(resp.data.success) {
						debugger;
						this.$data.comFormData = Object.assign(this.$data.comFormData, resp.data.data);
						this.$data.QuotationFrom.paramQuotation.carId = resp.data.data.id;
						this.$data.QuotationFrom.insurance = resp.data.data.insurance;
						this.$data.QuotationFrom.paramQuotation.contactPeople = resp.data.data.insured;
						this.$data.QuotationFrom.paramQuotation.contactPhone = resp.data.data.contactPhone;
					} else {
						this.$message.error(resp.data.msg);
					}
				}, function(error) {})
			},
			//保存
			save: function() {
				this.$refs.comForm.validate(function(valid, $event) {
					// 验证通过
					if(valid) {
						debugger;
						this.$data.QuotationFrom.paramQuotation.insuranceStartDate = this.moment(this.$data.QuotationFrom.paramQuotation.insuranceStartDate).format("YYYY-MM-DD");
						this.$http.post(this.API_ROOT + '/insurance/Quotation/save', this.$data.QuotationFrom)
							.then(resp => {
								if(resp.data.success) {
									debugger;
									this.companyQuery();
									this.$data.comFormShow = false;
								} else {
									this.$message.error(resp.data.msg);
								}
							}, resp => {

							});
					} else {
						return false
					}
				}.bind(this))
			},
		}
	}
</script>

<style>
</style>